package xm.components.spinner
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import xm.core.XMSprite;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 김정환
	 */	
	public class SpinnerListItemRenderer extends XMSprite
	{
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		/**
		 * 렌더링에 사용할 데이터. 
		 */		
		protected var data : Object;
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		
		private var _labelTF : TextField;
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function SpinnerListItemRenderer()
		{
			super();
		}
		
		
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
			
		}
		
		
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
		}
		
		
		/**
		 * @return : TextField - label 를 넣을 텍스트필드.
		 */		
		public function get labelField():TextField
		{
			if( _labelTF == null )
			{
				var tf : TextFormat = new TextFormat( "돋움", 16, 0x000000, true );
				_labelTF = new TextField();
				_labelTF.defaultTextFormat = tf;
				_labelTF.autoSize = TextFieldAutoSize.LEFT;
				_labelTF.selectable = false;
				addChild( _labelTF );
			}
			
			return _labelTF;
		}
		
		
		/**
		 * @param _data
		 */		
		public function set dataProvider( _data : Object ):void
		{
			data = _data;
			apply();
		}
		
		/**
		 * data : Object
		 */		
		public function get dataProvider():Object
		{
			return data;
		}
		
		
		/**
		 * apply - data 를 화면에 반영하는 과정.
		 */		
		public function apply():void
		{
			if( dataProvider && dataProvider is String )
			{
				labelField.text = dataProvider as String;
				
				labelField.width = labelField.textWidth + 4;
				labelField.height = labelField.textHeight + 4;
				
				labelField.x = ( viewWidth - labelField.width )/2;
				labelField.y = ( viewHeight - labelField.height )/2;
			}
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
		}
		
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
			
		}
		
		
		/**
		 * add
		 */		
		override public function add():void
		{
			super.add();
		}
		
		
		/**
		 * remove
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			
			
			data = null;
			
			
			if( _labelTF )
			{
				if( _labelTF.parent ) _labelTF.parent.removeChild( _labelTF );
				
				_labelTF = null;
			}
			
			
			
			super.destroy();
			
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		
		
		
		
		
		
	}
}